﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SP_XHWeb.Layouts.SP_XHWeb
{
    public partial class DispFormItem : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string webUrl = Request["web_url"].ToString();
            string listTitle = Request["list_title"].ToString();
            string itemID = Request["item_id"].ToString();
            string hostUrl = this.Page.Request.Url.Scheme + "://" + this.Page.Request.Url.Authority;
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(webUrl) && !string.IsNullOrEmpty(listTitle) && !string.IsNullOrEmpty(itemID) && !string.IsNullOrEmpty(hostUrl))
                {
                    using (SPSite site = new SPSite(hostUrl))
                    {
                        using (SPWeb web = site.OpenWeb(webUrl))
                        {
                            SPList list = web.Lists.TryGetList(listTitle);
                            if (list != null && list.ItemCount != 0)
                            {
                                foreach (SPListItem item in list.Items)
                                {
                                    if (int.Parse(item.ID.ToString()) == int.Parse(itemID))
                                    {
                                        lblTitle.InnerHtml = item.Title;
                                        lblContent.InnerHtml=item["Content"].ToString();
                                        lblCreateTime.InnerHtml = item["创建时间"].ToString();
                                        //try
                                        //{
                                        //    lblCreated.InnerHtml = item["Created"].ToString();
                                        //    lblCreatedBy.InnerHtml = item["Created By"].ToString().Substring(item["Created By"].ToString().IndexOf(";") + 2);
                                        //    lblModified.InnerHtml = item["Modified"].ToString();
                                        //    lblModifiedBy.InnerHtml = item["Modified By"].ToString().Substring(item["Modified By"].ToString().IndexOf(";") + 2);
                                        //}
                                        //catch
                                        //{
                                        //    lblCreated.InnerHtml = item["创建时间"].ToString();
                                        //    lblCreatedBy.InnerHtml = item["创建者"].ToString().Substring(item["创建者"].ToString().IndexOf(";") + 2);
                                        //    lblModified.InnerHtml = item["修改时间"].ToString();
                                        //    lblModifiedBy.InnerHtml = item["修改者"].ToString().Substring(item["修改者"].ToString().IndexOf(";") + 2);
                                        //}
                                        if (item.Fields.ContainsField("Picture"))
                                        {
                                            lblImg.InnerHtml = item["Picture"].ToString();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
